package com.cn.wanxi.test;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class MaxArray {
    public static void main(String[] args) {
        int length=getArrayLength();
        int [] arr=createArray(length);
        System.out.println("数组为:"+ Arrays.toString(arr));
        int max=maxArray(arr);
        System.out.println("最大值为："+max);
    }

    private static int maxArray(int[] arr) {
        int max=0;
        for (int i = 0; i < arr.length; i++) {
            max=max>arr[i]?max:arr[i];
        }
        return max;
    }

    private static int[] createArray(int length) {
        int[] arr=new int[length];
        Random random=new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i]=random.nextInt(99);
        }
        return arr;
    }

    private static int getArrayLength() {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入数组的长度");
        return scanner.nextInt();
    }
}
